package com.health.platform.common.sys.login.controller;

import com.health.platform.common.restful.AppResponse;
import com.health.platform.common.sys.login.entity.LoginEntity;
import com.health.platform.common.sys.login.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>登录Controller</p>
 * <p>创建日期：2021-02-07</p>
 *
 * @author zhou-qf
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录请求
     *
     * @param loginEntity 登录请求体
     * @return 登录结果
     */
    @PostMapping
    public AppResponse login(@RequestBody LoginEntity loginEntity){
        return loginService.login(loginEntity);
    }

    @RequestMapping("testLogin")
    public Map testLogin(@RequestBody LoginEntity loginEntity){
        Map<String, Object> map = new HashMap<>(3);
        map.put("success", "true");
        map.put("errorCode", "-1");
        map.put("msg", "操作成功");
        Map<String, String> body = new HashMap<>(3);
        body.put("userId", "1");
        body.put("username", "admin");
        body.put("token", "tokenStr");
        map.put("body", body);
        return map;
    }
}
